<?php
namespace app\admin\model;
use think\Db;
use app\admin\model\Common;
use think\Session;
use think\Validate;

class  Train extends Common
{   

  //个人所有信息
  public function AllTrain($param)
  {
    $name=$param['name'];
    $idnumber=$param['idnumber'];
    $train=Db::table('oa_admin_train')
           ->where('name',$name)
           ->where('idnumber',$idnumber)
           ->field('id,name,sex,nation,birth,politics,idnumber,sch,preoccupation,majoroccupation,majortime,jobrank,edu,degree,address,postalcode,office,phone,qq,email,fax,status')
           ->select();
     return $train;
  }


  //个人信息添加与修改
  public function ReviseTrain($param)
  {    
         $info['name']=$param['name'];
         $info['idnumber']=$param['idnumber'];
         $info['sex']=$param['sex'];
         $info['nation']=$param['nation'];
         $info['birth']=$param['birth'];
         $info['politics']=$param['politics']; 
         $info['sch']=$param['sch']; 
         $info['preoccupation']=$param['preoccupation']; 
         $info['majoroccupation']=$param['majoroccupation']; 
         $info['majortime']=$param['majortime'];
         $info['jobrank']=$param['jobrank'];
         $info['edu']=$param['edu'];
         $info['degree']=$param['degree'];
         $info['address']=$param['address'];
         $info['postalcode']=$param['postalcode'];
         $info['office']=$param['office'];
         $info['phone']=$param['phone'];
         $info['qq']=$param['qq'];
         $info['email']=$param['email'];
         $info['submit']=2;       
         $status=Db::table('oa_admin_train')
            ->where('name',$info['name'])
            ->where('idnumber',$info['idnumber'])
            ->field('status')
            ->select();
         if($status[0]['status']=='2')
          {
            $info['status']=4; 
            $info['ps']='个人信息';
          }if($status[0]['status']=='3'){
            $info['status']=1; 
          }if($status[0]['status']=='1'){
            $info['status']=1; 
          }
         $status1=Db::table('oa_admin_train')
            ->where('name',$info['name'])
            ->where('idnumber',$info['idnumber'])
            ->field('status1')
            ->select();
         if($status[0]['status1']=='2')
          {
            $info['status1']=4; 
            $info['ps']='个人信息';
          }if($status[0]['status1']=='3'){
            $info['status1']=1; 
          }if($status[0]['status1']=='1'){
            $info['status1']=1; 
          }

     $res= Db::table('oa_admin_train')
            ->where('name',$info['name'])
            ->where('idnumber',$info['idnumber'])
            ->find();
     if($res){   
       Db::table('oa_admin_train')
          ->where('name',$info['name'])
          ->where('idnumber',$info['idnumber'])
          ->update([
            'sex'=> $info['sex'],
            'nation'=> $info['nation'],
            'birth'=> $info['birth'], 
            'politics'=> $info['politics'], 
            'sch'=>$info['sch'],
            'preoccupation'=>$info['preoccupation'],
            'majoroccupation'=>$info['majoroccupation'],
            'majortime'=>$info['majortime'],
            'jobrank'=>$info['jobrank'],
            'edu'=>$info['edu'],
            'degree'=> $info['degree'],
            'address'=>$info['address'],
            'postalcode'=>$info['postalcode'],
            'office'=>$info['office'],
            'phone'=>$info['phone'],
            'qq'=>$info['qq'],
            'email'=>$info['email'],
            'status'=>$info['status'],
            'ps'=>$info['ps'],

          ]);

        return true;
        }else{
            return false;
          }
 }





//高校老师学校列表and教育厅学校列表
  public function SchlistTeacher($param)
  {   
      $map=[];
      $sch=(int)$param['sch'];
      $sch_name=$param['sch_name'];
      $sch_code=$param['sch_code'];


      if(isset($sch)&&$sch!='')//宣传部老师的学校信息
      {
        $map['sch_id']=(int)$param['sch'];
      }
      if(isset($sch_name)&&$sch_name!='')//教育厅查询
      {
        $map['sch_name']=['like', '%'.$sch_name.'%'];
      }
      if(isset($sch_code)&&$sch_code!='')
      {
        $map['sch_code']=['like', '%'.$sch_code.'%'];
      }
        $school=Db::table('oa_admin_school')
               ->where($map)
               ->paginate(config('pagesize'), false, ['page' => $page]);
      return $school;
  }
//高校老师学校信息修改and教育厅学校修改
    public function SchreviseTeacher($param)
  {  
    $sch=$param['sch'];
    $info['sch_province']=$param['sch_province'];
    $info['sch_type']=$param['sch_type'];  
    $info['sch_property']=$param['sch_property'];
    $info['sch_authorities']=$param['sch_authorities'];
    $info['sch_level']=$param['sch_level'];
    $info['sch_address']=$param['sch_address'];
    $info['sch_postal_address']=$param['sch_postal_address'];
    $info['sch_phone']=$param['sch_phone'];
    $info['sch_faxaphone']=$param['sch_faxaphone'];
    $info['sch_postal_code']=$param['sch_postal_code'];
     $res= Db::table('oa_admin_school')
            ->where('sch_name',$sch)
            ->find();
     if($res){
      Db::table('oa_admin_school')
          ->where('sch_name',$sch)
          ->update([
            'sch_province'=> $info['sch_province'],
            'sch_type'=> $info['sch_type'],
            'sch_property'=> $info['sch_property'], 
            'sch_authorities'=> $info['sch_authorities'], 
            'sch_level'=> $info['sch_level'], 
            'sch_address'=> $info['sch_address'], 
            'sch_postal_address'=> $info['sch_postal_address'], 
            'sch_phone'=> $info['sch_phone'], 
            'sch_faxaphone'=> $info['sch_faxaphone'], 
            'sch_postal_code'=> $info['sch_postal_code'], 
          ]);

        return true;
     }else{
      return false;
     }

  }
  //高校老师查询辅导员信息(查未审核)
  
  public function QueryTeacher($param)
    {
      $map=[];
      $map1=[];
      $name=$param['name'];
      $idnumber=$param['idnumber'];
      $sex=$param['sex'];
      $submit=$param['submit'];
      $sch=(int)$param['sch'];
      $sch_name=$param['sch_name'];
      if($param['sex'])
      {
        $map['sex']=$param['sex'];
      }
      if(isset($name)&&$name!='')
      {
        $map['name']=['like', '%'.$name.'%'];
      }
      if($param['idnumber'])
      {
        $map['idnumber']=['like', '%'.$idnumber.'%'];
      }
/*     if(isset($submit)&&$submit!='')
      {
        $map['submit']=$param['submit'];
      }*/
     if(isset($sch)&&$sch!='')
      {
        $map1=(int)$param['sch']; 
        $map['status']=1;
        $map['submit']=2;


      }else{
        $map['status']=2;
        $map['status1']=1;
        $a=['like', '%'.$sch_name.'%'];
        $b=Db::table('oa_admin_school')
                    ->where('sch_name',$a)
                    ->field('sch_id')
                    ->select();
        for($i=0;$i<count($b);$i++){
         $map1[$i]=$b[$i]['sch_id'];
        }
      }

    $train=Db::table('oa_admin_train')
           ->where($map)
           ->where('sch',"in",$map1)
           ->paginate(config('pagesize'), false, ['page' => $page]);
     return $train;
    }

     //高校老师对个人信息审核
  public function CheckTeacher($param)
  {
    $status= Db::table('oa_admin_train')
              ->where('id',"in",$param['id'])
              ->field('status')
              ->find();



     if($status['status']==$param['status']){
      return false;
     }else{

          Db::table('oa_admin_train')
              ->where('id',"in",$param['id'])
              ->update([
                'status'=>$param['status'],
              ]);
        return true;
      }

  }

       //教育厅对个人信息审核
  public function CheckEdu($param)
  {
    $status= Db::table('oa_admin_train')
              ->where('id',"in",$param['id'])
              ->field('status1')
              ->find();
     if($status['status1']==$param['status']){
      return false;
     }else{

          Db::table('oa_admin_train')
              ->where('id',"in",$param['id'])
              ->update([
                'status1'=>$param['status'],
              ]);
        return true;
      }

  }

  //高校老师与教育厅已审核列表与搜索
    public function ChecksearchTeacher($param)
        {
      $map=[];
      $map1=[];
      $name=$param['name'];
      $idnumber=$param['idnumber'];
      $sex=$param['sex'];
      $submit=$param['submit'];
      $sch=$param['sch'];
      $sch_name=$param['sch_name'];
      if($param['sex'])
      {
        $map['sex']=$param['sex'];
      }
      if(isset($name)&&$name!='')
      {
        $map['name']=['like', '%'.$name.'%'];
      }
      if($param['idnumber'])
      {
        $map['idnumber']=['like', '%'.$idnumber.'%'];
      }
/*     if(isset($submit)&&$submit!='')
      {
        $map['submit']=$param['submit'];
      }*/
     if(isset($sch)&&$sch!='')
      {
        $map1=$param['sch'];
        $map['status']=2;
      }else{
        $map['status']=2;
        $map['status1']=2;
        $a=['like', '%'.$sch_name.'%'];
        $b=Db::table('oa_admin_school')
                    ->where('sch_name',$a)
                    ->field('sch_id')
                    ->select();
        for($i=0;$i<count($b);$i++){
         $map1[$i]=$b[$i]['sch_id'];
        }
      }
      
    $train=Db::table('oa_admin_train')
           ->where($map)
           ->where('sch',"in",$map1)
           ->paginate(config('pagesize'), false, ['page' => $page]);
     return $train;
    }

    //高校老师录入辅导员信息
  public function WriteTeacher($param)
  {  
     $train=Db::table('oa_admin_train')
            ->where('idnumber',$param['idnumber'])
            ->where('name',$param['name'])
            ->find();
     if($train){
                 return false;
        }else{   $info['name']=$param['name'];
                 $info['idnumber']=$param['idnumber']; 
                 $info['sex']=$param['sex'];
                 $info['nation']=$param['nation'];
                 $info['birth']=$param['birth'];
                 $info['politics']=$param['politics']; 
                 $info['sch']=$param['sch']; 
                 $info['preoccupation']=$param['preoccupation']; 
                 $info['majoroccupation']=$param['majoroccupation']; 
                 $info['majortime']=$param['majortime'];
                 $info['jobrank']=$param['jobrank'];
                 $info['edu']=$param['edu'];
                 $info['degree']=$param['degree'];
                 $info['address']=$param['address'];
                 $info['postalcode']=$param['postalcode'];
                 $info['office']=$param['office'];
                 $info['phone']=$param['phone'];
                 $info['qq']=$param['qq'];
                 $info['email']=$param['email'];
                 $info['status']=1;
                 $info['submit']=1;
                 $info['status1']=1;
                    Db::table('oa_admin_train')
                           ->insert($info);
                $infoa['username']=$param['idnumber'];
                $infoa['password']="d93a5def7511da3d0f2d171d9c344e91";
                $infoa['create_time']=time();
                $infoa['realname']=$param['name'];
                $infoa['status']=1;
                $infoa['sch']=$param['sch'];
                $infoa['level']=1;
                Db::table('oa_admin_user')
                           ->insert($infoa);
                $userId = Db::name('user')->getLastInsID();
                $infob['user_id']=$userId;
                $infob['group_id']=18;
                Db::table('oa_admin_access')
                           ->insert($infob);
                 return true;
        }


  }


   //高校老师注销辅导员信息
  public function DeleteTeacher($param)
  {  
     if(isset($prarm['id'])&&(count($prarm['id'])!=0)){
     $result2=Db::table('oa_admin_exwork')
              ->where('train_id',"in",$param['id'])
              ->delete();
     $result3=Db::table('oa_admin_exedu')
              ->where('train_id',"in",$param['id'])
              ->delete();
     $result4=Db::table('oa_admin_exhonor')
              ->where('train_id',"in",$param['id'])
              ->delete();
     $result5=Db::table('oa_admin_exproject')
              ->where('train_id',"in",$param['id'])
              ->delete();
     $result6=Db::table('oa_admin_extrain')
              ->where('train_id',"in",$param['id'])
              ->delete();
     $result7=Db::table('oa_admin_exachievement')   
              ->where('train_id',"in",$param['id'])
              ->delete();
      $idnumber=Db::table('oa_admin_train')
              ->where('id',"in",$param['id'])
              ->field('idnumber')
              ->select();
              $a=count($idnumber);
      for($i=0;$i<$a;$i++){
        $idnumber1[$i]=$idnumber[$i]['idnumber'];

      }
         $data=Db::table('oa_admin_user')
              ->where('username',"in",$idnumber1)
              ->field('id')
              ->select();
              $b=count($data);
        for($j=0;$j<$b;$j++){
        $data1[$j]=$data[$j]['id'];

      }
     $result8=Db::table('oa_admin_user')
              ->where('username',"in",$idnumber1)
              ->delete();
     $result9=Db::table('oa_admin_access')
              ->where('user_id',"in",$data1)
              ->delete(); 
    $result1=Db::table('oa_admin_train')
              ->where('id',"in",$param['id'])
              ->delete();
       
     if(isset($result1)||isset($result2)||isset($result3)||isset($result4)||isset($result5)||isset($result6)||isset($result7)&&isset($result8)&&isset($result9))
     {
         return true;
     }
   }else{
    return false;
   }
  }
  //高校老师信息变更列表(个人信息)
  public function ChangelistTeacher($param)
  { 
     $map=[];
     if(isset($param['name'])&&$param['name']!='')
     {
      $map['name']=['like', '%'.$param['name'].'%'];
     }
     $a=4;
     $data1=Db::table('oa_admin_train')
              ->where('sch',$param['sch'])
              ->field('id')
              ->select();
      for($i=0;$i<count($data1);$i++)
      {
        $data2[$i]=$data1[$i]['id'];
      }

      $b1 = Db::name('admin_train')->where('id',"in",$data2)->where('status',$a)->field('id')->buildSql();
      $b2 = Db::name('admin_exachievement')->where('train_id',"in",$data2)->field('train_id')->where('status',$a)->buildSql();
      $b3 = Db::name('admin_exedu')->where('train_id',"in",$data2)->field('train_id')->where('status',$a)->buildSql();
      $b4 = Db::name('admin_exhonor')->where('train_id',"in",$data2)->field('train_id')->where('status',$a)->buildSql();
      $b5 = Db::name('admin_exproject')->where('train_id',"in",$data2)->field('train_id')->where('status',$a)->buildSql();
      $b6 = Db::name('admin_exwork')->where('train_id',"in",$data2)->field('train_id')->where('status',$a)->buildSql();
      $c = Db::name('admin_extrain')->where('train_id',"in",$data2)->field('train_id')->where('status',$a)->union([$b1, $b2,$b3,$b4,$b5,$b6])->buildSql();
      $data3 = Db::table($c . ' a')->select();
      for($i=0;$i<count($data3);$i++)
      {
        $data4[$i]=$data3[$i]['train_id'];
      }
      $data=Db::table('oa_admin_train')
             ->where('id',"in",$data4)
             ->where($map)
             ->field('id,sch,name,idnumber,majoroccupation,edu,office')
             ->paginate(config('pagesize'), false, ['page' => $page]);
      return $data;

  }
  //高校老师信息变更列表(修改信息)
  public function ChangeTeacher($param)
  {  
     if(isset($param['sch'])&&$param['sch']!='')
     {
      $b='status';
     }else{
      $b='status1';
     }
     $train_id=$param['id'];
     $a=4;
      $b1 = Db::name('admin_train')->where('id',$train_id)->where($b,$a)->field('id,name,updata_time,ps')->buildSql();
      $b2 = Db::name('admin_exachievement')->where('train_id',$train_id)->field('train_id,name,updata_time,ps')->where($b,$a)->buildSql();
      $b3 = Db::name('admin_exedu')->where('train_id',$train_id)->field('train_id,name,updata_time,ps')->where($b,$a)->buildSql();
      $b4 = Db::name('admin_exhonor')->where('train_id',$train_id)->field('train_id,name,updata_time,ps')->where($b,$a)->buildSql();
      $b5 = Db::name('admin_exproject')->where('train_id',$train_id)->field('train_id,name,updata_time,ps')->where($b,$a)->buildSql();
      $b6 = Db::name('admin_exwork')->where('train_id',$train_id)->field('train_id,name,updata_time,ps')->where($b,$a)->buildSql();
      $c = Db::name('admin_extrain')->where('train_id',$train_id)->field('train_id,name,updata_time,ps')->where('status',$a)->union([$b1, $b2,$b3,$b4,$b5,$b6])->buildSql();
      $data = Db::table($c . ' a')->paginate(config('pagesize'), false, ['page' => $page]);
      $temp = $data->toArray();
      $idnumber=Db::table('oa_admin_train')
                 ->field('id,idnumber')
                 ->select();


      for($i=0;$i<count($data);$i++)
      {
        for($j=0;$j<count($idnumber);$j++)
        {
          if($temp['data'][$i]['train_id']==$idnumber[$j]['id'])
          {
            $temp['data'][$i]['idnumber']=$idnumber[$j]['idnumber'];

          }
       }
      }
      return $temp;

  }
    //教育厅信息变更列表(个人信息)
  public function ChangelistEdu($param)
  { 
     $map=[];
     if(isset($param['name'])&&$param['name']!='')
     {
      $map['name']=['like', '%'.$param['name'].'%'];
     }
     $a=4;    
      $b1 = Db::name('admin_train')->where('status1',$a)->field('id')->buildSql();
      $b2 = Db::name('admin_exachievement')->field('train_id')->where('status1',$a)->buildSql();
      $b3 = Db::name('admin_exedu')->field('train_id')->where('status1',$a)->buildSql();
      $b4 = Db::name('admin_exhonor')->field('train_id')->where('status1',$a)->buildSql();
      $b5 = Db::name('admin_exproject')->field('train_id')->where('status1',$a)->buildSql();
      $b6 = Db::name('admin_exwork')->field('train_id')->where('status1',$a)->buildSql();
      $c = Db::name('admin_extrain')->field('train_id')->where('status1',$a)->union([$b1, $b2,$b3,$b4,$b5,$b6])->buildSql();
      $data3 = Db::table($c . ' a')->select();
      for($i=0;$i<count($data3);$i++)
      {
        $data4[$i]=$data3[$i]['train_id'];
      }
      $data=Db::table('oa_admin_train')
             ->where('id',"in",$data4)
             ->where($map)
             ->field('id,name,office,idnumber,sch,sex,edu,majoroccupation')
             ->select();
      return $data;

  }
  //教育厅对变更列表审核
  public function ChangecheckEdu($param)
  {
    if(isset($param['sch'])&&$param['sch']!='')
    {
      $a='status';
    }else{
      $a='status1';
    }  
       $res1=Db::table('oa_admin_train')
              ->where('id',"in",$param['id'])
              ->where($a,4)
              ->update([
                $a=>$param['status'],
              ]);
       $res2=Db::table('oa_admin_extrain')
              ->where('train_id',"in",$param['id'])
              ->where($a,4)
              ->update([
                $a=>$param['status'],
              ]);  
       $res3=Db::table('oa_admin_exproject')
              ->where('train_id',"in",$param['id'])
              ->where($a,4)
              ->update([
                $a=>$param['status'],
              ]); 
      $res4=Db::table('oa_admin_exhonor')
              ->where('train_id',"in",$param['id'])
              ->where($a,4)
              ->update([
                $a=>$param['status'],
              ]); 
      $res5=Db::table('oa_admin_exedu')
              ->where('train_id',"in",$param['id'])
              ->where($a,4)
              ->update([
                $a=>$param['status'],
              ]); 
      $res6=Db::table('oa_admin_exwork')
              ->where('train_id',"in",$param['id'])
              ->where($a,4)
              ->update([
                $a=>$param['status'],
              ]); 
     $res7=Db::table('oa_admin_exachievement')
              ->where('train_id',"in",$param['id'])
              ->where($a,4)
              ->update([
                $a=>$param['status'],
              ]); 
    if($res1||$res2||$res3||$res4||$res5||$res6||$res7){
      return true;  
    }else{
      return false;
    }
         
  }
  //高校老师与教育厅查询辅导员信息（做统计）
   public function QuerylistTeacher($param)
  {
      $map=[];
      $sch=$param['sch'];//高校老师给
      $sch_name=$param['sch_name'];//教育厅搜索
      $sch_address=$param['sch_address'];
      $name=$param['name'];
      $sex=$param['sex'];
      $nation=$param['nation'];
      $politics=$param['politics'];
      $majoroccupation=$param['majoroccupation'];
      $nation=$param['nation'];      
      $traindata_year=$param['traindata_year'];
      $traindata_name=$param['traindata_name'];


      if(isset($sch)&&$sch!='')
      {
        $school=(int)$sch;
      }else{
            if((isset($sch_address)&&$sch_address!='')||(isset($sch_name)&&$sch_name!=''))
            {
              $map1['sch_address']=$sch_address;
              $map1['sch_name']=['like', '%'.$sch_name.'%'];
              $school1=Db::table('oa_admin_school')
                   ->where($map1)
                   ->field('sch_id')
                   ->select();
                  for($i=0;$i<count($school1);$i++)
                  {
                    $school[$i]=$school1[$i]['sch_id'];
                  }
            }else{
              $school1=Db::table('oa_admin_school')
                   ->field('sch_id')
                   ->select();
                  for($i=0;$i<count($school1);$i++)
                  {
                    $school[$i]=$school1[$i]['sch_id'];
                  }

            }

         }
     if(($param['traindata_year'])||(isset($traindata_name)&&$traindata_name!='')){
       if($param['traindata_year']) {
         $a=$traindata_year.'-1-1';
        $c=$traindata_year+1;
        $b=$c.'-1-1';
        $start=date($a);
        $end=date($b);
        $map2['start_time']=['between time',[$start,$end]];
        $map3['start_time']=['between time',[$start,$end]];
      }
        
        $map2['traindata_name']=['like', '%'.$traindata_name.'%']; 
        $map3['traindata_name']=['like', '%'.$traindata_name.'%'];
        $extrain1=Db::table('oa_admin_extrain')
                   ->where($map2)
                   ->field('train_id')
                   ->select();
        $extrain2=Db::table('oa_admin_checkno')
                  ->alias('c')
                  ->join('oa_admin_traindata t','t.id=c.traindata_id')
                   ->where($map3)
                  ->where('t.status',2)
                  ->field('c.train_id')
                  ->select();
          for($i=0;$i<count($extrain2);$i++){
            array_push( $extrain1,$extrain2[$i]);
          }
        for($i=0;$i<count($extrain1);$i++)
        {
          $id[$i]=$extrain1[$i]['train_id'];
        }
      }else{
        $extrain1=Db::table('oa_admin_train')
                   ->field('id')
                   ->select();
        for($i=0;$i<count($extrain1);$i++)
        {
          $id[$i]=$extrain1[$i]['id'];
        }        
      }

      if($param['sex'])
      {
        $map['sex']=$param['sex'];
      }
      if(isset($name)&&$name!='')
      {
        $map['name']=['like', '%'.$name.'%'];
      }
     if(isset($nation)&&$nation!='')
      {
        $map['nation']=$param['nation'];
      }
     if(isset($politics)&&$politics!='')
      {
        $map['politics']=$param['politics'];
      }


    $train=Db::table('oa_admin_train')
           ->where($map)
           ->where('id',"in",$id)
           ->where('sch',"in",$school)
           ->field('id,sch,name,sex,politics,birth,majoroccupation,edu,degree')
           ->paginate(config('pagesize'), false, ['page' => $page]);
      return $train;
   }  
   //统计需要的下拉列表
    public function YearTeacher(){
      $year=Db::table('oa_admin_extrain')
            ->field('start_time')
            ->select();
      for($i=0;$i<count($year);$i++)
      {
        $sub=substr($year[$i]['start_time'],0,4);
        $year1[$i]=$sub;

      }
      $year2=array_unique($year1);
      sort($year2);
      for($i=0;$i<count($year2);$i++)
      {
        $year3[$i]['year_id']=$i+1;
        $year3[$i]['year']=$year2[$i];
      }
      $data['year']=$year3;

      $sch_address=Db::table('oa_admin_school')
            ->field('sch_address')
            ->distinct(true)
            ->select();

      for($i=0;$i<count($sch_address);$i++)
      { 
        $sch_address[$i]['sch_address_id']=$i+1;
      }

      /*$data['sch_address']=$sch_address1;*/
      $data['sch_address']=$sch_address;


       $politics[0]['politics']='中共党员';
       $politics[1]['politics']='中共预备党员';
       $politics[2]['politics']='共青团员';
       $politics[3]['politics']='群众';
       $politics[4]['politics']='民革党员';
       $politics[5]['politics']='民盟盟员';
       $politics[6]['politics']='民建会员';
       $politics[7]['politics']='民进会员';
       $politics[8]['politics']='农工党党员';
       $politics[9]['politics']='致公党党员';
       $politics[10]['politics']='九三学社社员';
       $politics[11]['politics']='台盟盟员';
       $politics[12]['politics']='无党派人士';
       $politics[13]['politics']='其他';
       for($i=0;$i<count($politics);$i++)
       {
        $politics[$i]['politics_id']=$i+1;
       }
       $data['politics']=$politics;

      return $data;


    }
    

  

  //---教育厅学校信息维护---
  
  //增加学校
   public function WriteEdusch($param)
  {
    $sch1=Db::table('oa_admin_school')
              ->where('sch_code',$param['sch_code'])
              ->find();

    $sch2=Db::table('oa_admin_school')
              ->where('sch_name',$param['sch_name'])
              ->find();
    if($sch1||$sch2){
      return false;
    }
    $info['sch_code']=$param['sch_code'];
    $info['sch_name']=$param['sch_name'];
    $info['sch_province']=$param['sch_province'];
    $info['sch_type']=$param['sch_type'];  
    $info['sch_property']=$param['sch_property'];
    $info['sch_authorities']=$param['sch_authorities'];
    $info['sch_level']=$param['sch_level'];
    $info['sch_address']=$param['sch_address'];
    $info['sch_postal_address']=$param['sch_postal_address'];
    $info['sch_phone']=$param['sch_phone'];
    $info['sch_faxaphone']=$param['sch_faxaphone'];
    $info['sch_postal_code']=$param['sch_postal_code'];
    Db::table('oa_admin_school')
                   ->insert($info);
     return true;

  }

  //学校列表（与老师列表相同）
  //修改学校信息（与老师修改相同）
  //学校信息删除
   public function DeleteEdusch($param)
  {
    $result1 = Db::table('oa_admin_school')
              ->where('sch_id', "in", $param['sch_id'])
              ->delete();
    if($result1){
      return true;
    }else{
      return false;
    }
  }

  //导入个人信息
public function ImportTrain($param)
{
  $error = [];
  for($i=0;$i<count($param);$i++){
        $traindata=Db::table('oa_admin_train')
                                ->where('idnumber',$param[$i]['idnumber'])
                                ->find();
           if($traindata){
              array_push($error, ['index' => $param[$i]['index'], 'msg' => '身份证已存在']);
                    // $this->error = '下标为【 ' .($i + 1) . ' 】的用户【 身份证 】已存在,导入失败';
              }else{   $info['name']=$param[$i]['name'];
                       $info['idnumber']=$param[$i]['idnumber']; 
                       $info['sex']=$param[$i]['sex'] == '男' ? 1 : $param[$i]['sex'] == '女' ? 2 : null;
                       $info['nation']=$param[$i]['nation'];
                       if (!empty($param[$i]['birth'])) {
                          $info['birth']=$param[$i]['birth'];
                        }
                       $info['politics']=$param[$i]['politics']; 
                       $info['sch']=$param[$i]['sch']; 
                       $info['preoccupation']=$param[$i]['preoccupation']; 
                       $info['majoroccupation']=$param[$i]['majoroccupation'];
                       if (!empty($param['majortime'])) {
                       $info['majortime']=$param[$i]['majortime'];
                     }
                       $info['jobrank']=$param[$i]['jobrank'];
                       $info['edu']=$param[$i]['edu'];
                       $info['degree']=$param[$i]['degree'];
                       $info['address']=$param[$i]['address'];
                       $info['postalcode']=$param[$i]['postalcode'];
                       $info['office']=$param[$i]['office'];
                       $info['phone']=$param[$i]['phone'];
                       $info['qq']=$param[$i]['qq'];
                       $info['email']=$param[$i]['email'];
                       $info['status']=1;
                       $info['status1']=1;
                       $info['submit']=1;
                       $info['updata_time']=date('Y-m-d');

                          Db::table('oa_admin_train')
                                 ->insert($info);
                      $infoa['username']=$param[$i]['idnumber'];
                      $infoa['password']=user_md5('123456');
                      $infoa['create_time']=time();
                      $infoa['realname']=$param[$i]['name'];
                      $infoa['sch']=$param[$i]['sch'];
                      $infoa['status']=1;
                      $infoa['level']=1;
                      Db::table('oa_admin_user')
                                 ->insert($infoa);
                      $userId = Db::name('user')->getLastInsID();
                      $infob['user_id']=$userId;
                      $infob['group_id']=18;
                      Db::table('oa_admin_access')
                                 ->insert($infob);
          }
     }
     if (count($error) > 0) {
       return ['isSuccess' => false, 'errorList' => $error];
     }
     return ['isSuccess' => true];
}

//个人所有信息
  public function ListTrain($param){
    $id=$prarm['id'];
    $train=Db::table('oa_admin_train')
              ->where('id',$param['id'])
              ->select();
    $exedu=Db::table('oa_admin_exedu')
              ->where('train_id',$param['id'])
              ->select();
    $exhonor=Db::table('oa_admin_exhonor')
              ->where('train_id',$param['id'])
              ->select();
    $exproject=Db::table('oa_admin_exproject')
              ->where('train_id',$param['id'])
              ->select();
    $extrain=Db::table('oa_admin_extrain')
              ->where('train_id',$param['id'])
              ->select();
    $exwork=Db::table('oa_admin_exwork')
              ->where('train_id',$param['id'])
              ->select();
    $exachievement=Db::table('oa_admin_exachievement')
              ->where('train_id',$param['id'])
              ->select();
    $data['train']=$train;
    $data['exedu']=$exedu; 
    $data['exhonor']=$exhonor;                                                         
    $data['exproject']=$exproject; 
    $data['extrain']=$extrain; 
    $data['exwork']=$exwork; 
    $data['exachievement']=$exachievement; 
    return $data;

 }
}